package com.blackangel

import org.springframework.context.ApplicationContext
import org.springframework.context.support.ClassPathXmlApplicationContext
import com.blackangel.model.Address
import com.blackangel.model.GormUser

/**
 * Created by IntelliJ IDEA.
 * User: blackangel
 * Date: 11-11-25
 * Time: 上午10:29
 * To change this template use File | Settings | File Templates.
 */
class Test {
    static void main(String[] art){
        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml")
        GormUser.withTransaction{
            GormUser user=new GormUser()
//            user.id=2
//            user.version=0
            user.dateCreated=new Date()
            user.name="121"
            try{
                user.save(flush: true, failOnError: true,validate:false)
            }catch (Exception e){
                e.printStackTrace()
            }

//            Address adde=new Address(name: "1",details: "1")
//            user.addToAddress(adde)
//            user.save(flush:true,failsOnError:true)
        }
        GormUser.list()?.each {
            println it.name
        }
    }
}
